package in.ac.dei.edrp.purchase.flexFieldSettings.keyFlexFieldMaster;


import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import flex.messaging.FlexSession;
import flex.messaging.FlexContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.flex.remoting.RemotingDestination;
import org.springframework.stereotype.Controller;


@Controller
@RemotingDestination("keyFlexFieldSegmentDestination")
public class keyFlexFieldSegmentController {
	@Autowired
	@Qualifier("keyFlexFieldSegmentDaoImpl")
	
	private keyFlexFieldSegmentDao flexFieldDao;
	
	public List<keyFlexFieldSegmentBean> loadStructureGrid(Map<String, String> obj)
	{
		System.out.println("Inside loadStructureGrid");
		keyFlexFieldSegmentBean bean = new keyFlexFieldSegmentBean();
		FlexSession session = FlexContext.getFlexSession();
		bean.setApplicationId(obj.get("applicationId"));
		bean.setOrganizationId(session.getAttribute("universityCode").toString());
		bean.setUserId(session.getAttribute("userId").toString());
		bean.setFlexFieldId(obj.get("flexFieldId"));
		
		System.out.println("load Structure Grid  :: " + obj.get("flexFieldId") + " : " + obj.get("applicationId"));
		List<keyFlexFieldSegmentBean> list = flexFieldDao.loadStructureGrid(bean);
		return list; 
	}
	
	
	public List<keyFlexFieldSegmentBean> getAppIdFlexFieldId()
	{
		System.out.println("Inside getAppIdFlexFieldId");
		keyFlexFieldSegmentBean bean = new keyFlexFieldSegmentBean();
		FlexSession session = FlexContext.getFlexSession();
		//bean.setApplicationId(obj.get("applicationId"));
		bean.setOrganizationId(session.getAttribute("universityCode").toString());
		bean.setUserId(session.getAttribute("userId").toString());
		
		List<keyFlexFieldSegmentBean> list = flexFieldDao.getAppIdFlexFieldId(bean);
		return list; 
	}
	public List<keyFlexFieldSegmentBean> getFlagStatus(Map<String, String> obj)
	{
		System.out.println("Inside getFlagStatus");
		keyFlexFieldSegmentBean bean = new keyFlexFieldSegmentBean();
		FlexSession session = FlexContext.getFlexSession();
		bean.setApplicationId(obj.get("applicationId"));
		bean.setOrganizationId(session.getAttribute("universityCode").toString());
		bean.setUserId(session.getAttribute("userId").toString());
		bean.setFlexFieldId(obj.get("flexFieldId"));
		bean.setFlexFieldCode(obj.get("flexFieldCode"));
		System.out.println("hi " + obj.get("flexFieldId") + " " + obj.get("flexFieldCode") );
		List<keyFlexFieldSegmentBean> list = new ArrayList<keyFlexFieldSegmentBean>();
		list = flexFieldDao.getFlagStatus(bean);
		//System.out.println("  " + bean.getAllowDynamicInsertsFlag() + "  " + bean.getCompileFlag() + "  " + bean.getFreezeFlexFieldsFlag() + " " + bean.getFreezeRollUpGroupsFlag());
		return list; 
	}
	public String insertRow(Map<String, String> obj)
	{	
		System.out.println("Inside insertRow");
		String str = "";
		FlexSession session = FlexContext.getFlexSession();
		keyFlexFieldSegmentBean bean = new keyFlexFieldSegmentBean();
		bean.setFlexFieldId(obj.get("flexFieldId"));
		bean.setApplicationId(obj.get("applicationId"));
		bean.setOrganizationId(session.getAttribute("universityCode").toString());
		bean.setUserId(session.getAttribute("userId").toString());
		bean.setModifierId(session.getAttribute("modifierId").toString());
		bean.setFlexFieldCode(obj.get("flexFieldCode"));
		bean.setFlexFieldTitle(obj.get("flexFieldTitle"));
		bean.setFreezeFlexFieldsFlag(obj.get("freezeFlexFieldsFlag"));
		bean.setFreezeRollUpGroupsFlag(obj.get("freezeRollUpGroupsFlag"));
		bean.setFlexFieldDescription(obj.get("flexFieldDescription"));
		bean.setEnabledStatusFlag(obj.get("enabledStatusFlag"));
		bean.setAllowDynamicInsertsFlag(obj.get("allowDynamicInsertsFlag"));
		str = flexFieldDao.insertRow(bean);
//		List<keyFlexFieldSegmentBean> list = flexFieldDao.insertRow(bean);
		return str; 
	}
	
	public String editRow(Map<String, String>obj)
	{
		System.out.println("Inside editRow");
		String str = "";
		FlexSession session = FlexContext.getFlexSession();
		keyFlexFieldSegmentBean bean = new keyFlexFieldSegmentBean();
		bean.setFlexFieldId(obj.get("flexFieldId"));
		bean.setFlexFieldCode(obj.get("flexFieldCode"));
		bean.setFlexFieldTitle(obj.get("flexFieldTitle"));
		bean.setApplicationId(obj.get("applicationId"));
		bean.setOrganizationId(session.getAttribute("universityCode").toString());
		bean.setUserId(session.getAttribute("userId").toString());
		bean.setModifierId(session.getAttribute("modifierId").toString());
		bean.setFreezeFlexFieldsFlag(obj.get("freezeFlexFieldsFlag"));
		bean.setFreezeRollUpGroupsFlag(obj.get("freezeRollUpGroupsFlag"));
		bean.setFlexFieldDescription(obj.get("flexFieldDescription"));
		bean.setEnabledStatusFlag(obj.get("enabledStatusFlag"));
		bean.setOldCode(obj.get("oldCode"));
		bean.setOldTitle(obj.get("oldTitle"));
		System.out.println("Inside editRow  " + obj.get("oldCode") + "  " + obj.get("oldTitle"));
		bean.setAllowDynamicInsertsFlag(obj.get("allowDynamicInsertsFlag"));
		str = flexFieldDao.editRow(bean);
//		List<keyFlexFieldSegmentBean> list = flexFieldDao.insertRow(bean);
		return str; 
	}
	public List<keyFlexFieldSegmentBean> validateValueSet(Map<String, String> obj)
	{
		System.out.println("Inside validateValueSet");
		keyFlexFieldSegmentBean bean = new keyFlexFieldSegmentBean();
		FlexSession session = FlexContext.getFlexSession();
		bean.setFlexFieldId(obj.get("flexFieldId"));
		bean.setFlexFieldCode(obj.get("flexFieldCode"));
		bean.setApplicationId(obj.get("applicationId"));
		bean.setOrganizationId(session.getAttribute("universityCode").toString());
		bean.setUserId(session.getAttribute("userId").toString());
		System.out.println("hi " + obj.get("flexFieldId") + "  " + obj.get("flexFieldCode") );
		List<keyFlexFieldSegmentBean> list = new ArrayList<keyFlexFieldSegmentBean>();
		list = flexFieldDao.validateValueSet(bean);
		//System.out.println("  " + bean.getAllowDynamicInsertsFlag() + "  " + bean.getCompileFlag() + "  " + bean.getFreezeFlexFieldsFlag() + " " + bean.getFreezeRollUpGroupsFlag());
		return list; 
	}

	public List<keyFlexFieldSegmentBean> validateSegmentSummary(Map<String, String> obj)
	{
		System.out.println("Inside validateSegmentSummary");
		keyFlexFieldSegmentBean bean = new keyFlexFieldSegmentBean();
		FlexSession session = FlexContext.getFlexSession();
		bean.setFlexFieldId(obj.get("flexFieldId"));
		bean.setFlexFieldCode(obj.get("flexFieldCode"));
		bean.setApplicationId(obj.get("applicationId"));
		bean.setOrganizationId(session.getAttribute("universityCode").toString());
		bean.setUserId(session.getAttribute("userId").toString());
		System.out.println("hi " + obj.get("flexFieldId") + "   " + obj.get("flexFieldCode") );
		List<keyFlexFieldSegmentBean> list = new ArrayList<keyFlexFieldSegmentBean>();
		list = flexFieldDao.validateSegmentSummary(bean);
		//System.out.println("  " + bean.getAllowDynamicInsertsFlag() + "  " + bean.getCompileFlag() + "  " + bean.getFreezeFlexFieldsFlag() + " " + bean.getFreezeRollUpGroupsFlag());
		return list; 
	}

	
}

